namespace DotNetNuke.UI.Utilities
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Web;
    using System.Web.Caching;

    public class DataCache
    {
        public static object GetCache(string CacheKey)
        {
            return HttpRuntime.Cache[CacheKey];
        }

        public static void RemoveCache(string CacheKey)
        {
            Cache objCache = HttpRuntime.Cache;
            if (objCache[CacheKey] != null)
            {
                objCache.Remove(CacheKey);
            }
        }

        public static void SetCache(string CacheKey, object objObject)
        {
            HttpRuntime.Cache.Insert(CacheKey, RuntimeHelpers.GetObjectValue(objObject));
        }

        public static void SetCache(string CacheKey, object objObject, DateTime AbsoluteExpiration)
        {
            HttpRuntime.Cache.Insert(CacheKey, RuntimeHelpers.GetObjectValue(objObject), null, AbsoluteExpiration, Cache.NoSlidingExpiration);
        }

        public static void SetCache(string CacheKey, object objObject, int SlidingExpiration)
        {
            HttpRuntime.Cache.Insert(CacheKey, RuntimeHelpers.GetObjectValue(objObject), null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds((double) SlidingExpiration));
        }

        public static void SetCache(string CacheKey, object objObject, CacheDependency objDependency)
        {
            HttpRuntime.Cache.Insert(CacheKey, RuntimeHelpers.GetObjectValue(objObject), objDependency);
        }

        public static void SetCache(string CacheKey, object objObject, CacheDependency objDependency, DateTime AbsoluteExpiration, TimeSpan SlidingExpiration)
        {
            HttpRuntime.Cache.Insert(CacheKey, RuntimeHelpers.GetObjectValue(objObject), objDependency, AbsoluteExpiration, SlidingExpiration);
        }
    }
}

